﻿using HBKY.Shop.Model;
using Newtonsoft.Json;

namespace HBKY.Shop.Common
{

    /// <summary>
    /// 通用返回实体
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ResponseMessage<T>
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public int Code { get; set; } = 200;
        
        /// <summary>
        ///返回消息
        /// </summary>
        public string Message { get; set; }
      
        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 数据总数
        /// </summary>
        public T Data { get; set; }
    }

    public class ResponseMessageItem
    {
        public int ResponseCode { get; set; }
        public string Message { get; set; }
    }

    public static class BaseResponse
    {
        public static ResponseMessage<T> Success<T>(this T body, string message = MessageModel.Success, bool success = true, int code = 200)
        {
            return new ResponseMessage<T> 
            {
                Success =success,
                Code = code,
                Message = message,
                Data = body
            };
        }
    }
}
